package com.ptswitch.material.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.hxzon.project.EHibernateDaoSupport;
import com.hxzon.util.StringUtil;
import com.ptswitch.material.dao.MaterialDao;
import com.ptswitch.material.model.Material;

@Repository("materialDao")
public class MaterialHibernate extends EHibernateDaoSupport<Material> implements MaterialDao {

	public Material getByCode(String code) {
		code = StringUtil.escapeSql(code);
		List<Material> list = getList(" where p.code='" + code + "'", -1, -1);
		if (list.isEmpty()) {
			return null;
		}
		if (list.size() > 1) {
			logger.error("material[{}] not unique", code);
		}
		return list.get(0);
	}
	
	public List<Material> getByPcbDecal(String pcbDecal) {
		pcbDecal = StringUtil.escapeSql(pcbDecal);
		return getList(" where p.pcbDecal='" + pcbDecal + "'", -1, -1);
	}

	public String orderBy() {
		return " order by p.code ";
	}

}
